package com.emokili.ewa.portal.controller;


import com.emokili.ewa.common.utils.R;
import com.emokili.ewa.core.frame.entity.MemberEntity;
import com.emokili.ewa.core.frame.entity.MemberFrameEntity;
import com.emokili.ewa.core.frame.service.FrameService;
import com.emokili.ewa.core.frame.service.MemberFrameService;
import com.emokili.ewa.core.frame.vo.FrameDetailVo;
import com.emokili.ewa.core.frame.vo.FrameOnlineStatusVo;
import com.emokili.ewa.core.frame.vo.FrameOutVo;
import com.emokili.ewa.core.frame.vo.FrameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/v1/frame")
public class FrameController {

    @Autowired
    private MemberFrameService memberFrameService;
    @Autowired
    private FrameService frameService;

    @RequestMapping("/bind/status/{serialNumber}")
    @ResponseBody
    public R getBindStatus(@PathVariable String serialNumber){
        memberFrameService.getBindStatus(serialNumber);
        return R.ok();
    }

    @GetMapping("online-status")
    public R onlineStatus(HttpServletRequest request){
        MemberEntity entity = (MemberEntity) request.getAttribute("member");
        List<FrameOnlineStatusVo> onlineStatus = frameService.getOnlineStatus(entity.getId());
        return R.ok().setData(onlineStatus);
    }

    /**
     * 相框设置
     * @param frameVo
     * @return
     */
    @PostMapping("/settings")
    @ResponseBody
    public R settings(@RequestBody FrameVo frameVo){
        frameService.update(frameVo);
        return R.ok();
    }

    @GetMapping("/frames")
    public R frames(HttpServletRequest request){
        MemberEntity entity = (MemberEntity) request.getAttribute("member");
        List<FrameOutVo> list = frameService.list(entity.getId());
        return R.ok().setData(list);
    }

    @GetMapping("/detail")
    public R detail(Long serialNumber){
        FrameDetailVo detail = frameService.detail(serialNumber);
        return R.ok().setData(detail);
    }
}
